local monao = fk.CreateSkill{
    name = "steam__monao",
    dynamic_desc = function(self, player)
        if player:getMark("steam__monao") == 1 then--背水
            return "steam__monao_hasbeishui"
        else
            return "steam__monao_nobeishui"
        end
    end,
}

-- 添加luan函数用于管理表的大小
local function luan(t, value)
    if not t then t = {} end
    table.insert(t, value)
    if #t > 2 then
        table.remove(t, 1)
    end
    return t
end

Fk:loadTranslationTable{
    ["steam__monao"] = "莫恼",
    [":steam__monao"] = "你造成伤害时，可防止之，然后选择一项：1.摸两张牌；2.回复1点体力。背水：将此词条移至“孟明视”的一个相邻技能描述中。",
    ["#steam__monao"] = "莫恼",
    ["#steam__monao-choice"] = "莫恼：请选择一项",
    ["monao_draw"] = "摸两张牌",
    ["monao_recover"] = "回复1点体力",
    ["mengmingshi_beishui"] = "背水：将此词条移至“孟明视”的一个相邻技能描述中。",
    [":steam__monao_hasbeishui"] = "你造成伤害时，可防止之，然后选择一项：1.摸两张牌；2.回复1点体力。背水：将此词条移至“孟明视”的一个相邻技能描述中。",
    [":steam__monao_nobeishui"] = "你造成伤害时，可防止之，然后选择一项：1.摸两张牌；2.回复1点体力。",

}

monao:addAcquireEffect(function(self,player)
    local room = player.room
    room:setPlayerMark(player,"steam__monao",1)

end)

monao:addEffect(fk.DamageCaused, {
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self.name) and target == player
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        if not room:askToSkillInvoke(player, {
            skill_name = monao.name,
          }) then
            return false
          end
        local ch={
            "monao_draw",
            "monao_recover",
        }
        if player:getMark(monao.name) == 1 then
            table.insert(ch,"mengmingshi_beishui")
        end
        local choice = room:askForChoice(player, ch, self.name, "#steam__monao-choice")
        if choice then
            event:setCostData(self,choice)
            return true
        end
        return false
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local choice = event:getCostData(self)
        local record=player:getTableMark("@fenzhou_record")
        record=luan(record,"steam__monao")
        room:setPlayerMark(player,"@fenzhou_record",record)
        -- 防止伤害
        data:preventDamage()
        
        -- 执行选择的效果
        --若背水则移除
        if choice == "mengmingshi_beishui" then
            room:setPlayerMark(player,monao.name,0)
            room:setPlayerMark(player,"steam__qiedai",1)
        end
        if choice ~= "monao_recover" then
            player:drawCards(2, self.name)
        end
        if choice ~= "monao_draw" then
            room:recover({
                who = player,
                num = 1,
                recoverBy = player,
                skillName = self.name,
            })
        end
    end,
})

return monao 